//SET DIRECTORY FIRST
*cd " "
use "Vincent&Mango_DataFile1.dta" , clear // ---> See File "Vincent&Mango_DataFile1_Sources" for data data sources, collection, and treatment

//DECLARE PANEL DATA
encode ccode , gen(ncountry)
xtset ncountry year , yearly

********************************************* DATA STRUCTURE CHECK ******************************************************
//GO TO LINE 140 FOR THE APPLICATION OF THE CPSE MODEL

//1) CHECK FOR PANEL STRUCTURE

//1.A. STATIONARY (Unit Root test)

*Im-Pesaran-Shin
xtunitroot ips rp , replace
xtunitroot ips sng_pc_usr
xtunitroot ips cg_pc_usr
xtunitroot ips gdp_pc_usr
xtunitroot ips rr
xtunitroot ips ren_tot
xtunitroot ips serv_gdp
xtunitroot ips pop_den
xtunitroot ips etax_gdp
*xtunitroot ips randd_gdp // not enough observations
xtunitroot ips sng_gdp
xtunitroot ips cg_gdp

*Fisher-type (ADF)
xtunitroot fisher rp , dfuller lags(0)
xtunitroot fisher sng_pc_usr , dfuller lags(0)
xtunitroot fisher cg_pc_usr , dfuller lags(0)
xtunitroot fisher gdp_pc_usr , dfuller lags(0)
xtunitroot fisher rr , dfuller lags(0)
xtunitroot fisher ren_tot , dfuller lags(0)
xtunitroot fisher serv_gdp , dfuller lags(0)
xtunitroot fisher pop_den , dfuller lags(0)
xtunitroot fisher etax_gdp , dfuller lags(0)
xtunitroot fisher randd_gdp , dfuller lags(0)
xtunitroot fisher sng_gdp , dfuller lags(0)
xtunitroot fisher cg_gdp , dfuller lags(0)

*Fisher-type (PP) --> Results consistent with ADF --> Don't report
xtunitroot fisher sng_pc_usr , pperron lags(0)
xtunitroot fisher cg_pc_usr , pperron lags(0)
xtunitroot fisher gdp_pc_usr , pperron lags(0)
xtunitroot fisher rr , pperron lags(0)
xtunitroot fisher ren_tot , pperron lags(0)
xtunitroot fisher serv_gdp , pperron lags(0)
xtunitroot fisher pop_den , pperron lags(0)
xtunitroot fisher etax_gdp , pperron lags(0)
xtunitroot fisher randd_gdp , pperron lags(0)
xtunitroot fisher sng_gdp , pperron lags(0)
xtunitroot fisher cg_gdp , pperron lags(0)


//1.B. COINTEGRATION
*Kao
xtcointtest kao rp sng_pc_usr cg_pc_usr gdp_pc_usr , replace
xtcointtest kao rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
xtcointtest kao rp sng_gdp cg_gdp gdp_pc_usr
xtcointtest kao rp sng_gdp cg_gdp gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp


//1.C. MULTICOLLINEARITY 

*1.C.1 Correlation Matrix
corr sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp sng_gdp cg_gdp

*1.C.2 VIF

//Short model
reg rp sng_pc_usr cg_pc_usr gdp_pc_usr
estat vif

//Long model
reg rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif

//Short model // RELATIVE EXPENDITURES
reg rp sng_gdp cg_gdp gdp_pc_usr
estat vif

//Long model // RELATIVE EXPENDITURES
reg rp sng_gdp cg_gdp gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif


//1.D HETEROSKEDASTICITY

*1.D.1 WALD TEST
  * p < 0.05 --> Heterokedastic
  * p > 0.05 --> Homocedastic

*Long model
xtreg rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , fe 
xttest3

*1.D.2 LIKELIHOOD-RATIO 
  * p < 0.05 --> Heteroskedastic
  * p > 0.05 --> Homoskedastic

*Long Model
set more off
xtgls rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , igls panels(hetero)
estimate store hetero
xtgls rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , igls
estimate store homo
local df=e(N_g)-1
lrtest hetero homo , df(104)


//1.E AUTOCORRELATION
*p < 0.05 --> First-order Autocorrelation
*p > 0.05 --> No First-order Autocorrelation
	
*Long model
xtserial rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp


//1.F. CROSS-SECTIONAL DEPENDENCE

*1.F.1 LAGRANGIAN MULTIPLIER
  * p<0.05 cross sectional dependence
  * p>0.05 cross sectional independence
 
*Long Model
xtreg rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp etax_gdp randd_gdp , re
xttest0 

*1.F.2 PESARAN
*Long model
xtreg rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp etax_gdp randd_gdp , re
xtcsd , pesaran abs



********************************************* CORRECTED PANEL STANDARD ERRORS ******************************************************
//SET DIRECTORY FIRST
*cd " "
use "Vincent&Mango_DataFile1.dta" , clear

//DECLARE PANEL DATA
encode ccode , gen(ncountry)
xtset ncountry year , yearly

//1) RESEARCH QUESTION 1: MARGINAL EFFECT OF SNG ON RP
set more off
*Short Model
xtpcse rp sng_pc_usr cg_pc_usr gdp_pc_usr , correlation(ar1) replace
eststo pcse_short
*Long Model
xtpcse rp sng_pc_usr cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax randd , correlation(ar1)
eststo pcse_long
esttab pcse_short pcse_long , mti ( Short Long ) star ( * 0.1 ** 0.05 *** 0.01 ) r2


//2) SUB-RESEARCH QUESTION 1
gen period = 1 if year > 2009
replace period = 0 if period == .

set more off
*Short Model
asdoc xtpcse rp c.sng_pc_usr##i.period cg_pc_usr gdp_pc_usr , correlation(ar1) replace
eststo pcse_short_p
*Long Model
asdoc xtpcse rp c.sng_pc_usr##i.period cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax randd , correlation(ar1)
eststo pcse_long_p
esttab pcse_short_p pcse_long_p , mti ( Short Long ) star ( * 0.1 ** 0.05 *** 0.01 ) r2


//3) SUB-RESEARCH QUESTION 2
use "Vincent&Mango_DataFile2.dta" , clear // ---> See File "Vincent&Mango_DataFile2_Sources" for data sources, collection, and treatment

//DECLARE PANEL DATA
encode ccode , gen(ncountry)
xtset ncountry year , yearly

//1) 1-DIGIT
gen sng_ec = sng_402 + sng_403 + sng_405
gen sng_env = sng_501 + sng_502 + sng_503 + sng_504 + sng_505 + sng_506
gen sng_hca = sng_601 + sng_602 + sng_603 + sng_604
gen cg_ec = cg_402 + cg_403 + cg_405
gen cg_env = cg_501 + cg_502 + cg_503 + cg_504 + cg_505 + cg_506
gen cg_hca = cg_601 + cg_602 + cg_603 + cg_604
format sng* cg* %10.1fc
 
set more off
xtpcse rp sng_ec sng_env sng_hca cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1) replace
eststo mod1
xtpcse rp sng_ec sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod2
xtpcse rp sng_402 sng_403 sng_405 sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod3
xtpcse rp sng_ec sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod4
xtpcse rp sng_ec sng_env sng_601 sng_602 sng_603 sng_604 cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod5
esttab mod* , mti ( 1 3 4 5 6 ) star ( * 0.1 ** 0.05 *** 0.01 ) r2

xtpcse rp cg_ec cg_env cg_hca sng_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1) replace
eststo mod1
xtpcse rp cg_ec cg_env cg_hca sng_ec sng_env sng_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod2
xtpcse rp cg_402 cg_403 cg_405 cg_env cg_hca sng_ec sng_env sng_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod3
xtpcse rp cg_ec cg_501 cg_502 cg_503 cg_504 cg_505 cg_506 cg_hca sng_ec sng_env sng_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod4
xtpcse rp cg_ec cg_env cg_601 cg_602 cg_603 cg_604 sng_ec sng_env sng_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp , correlation(ar1)
eststo mod5
esttab mod* , mti ( 1 3 4 5 5 ) star ( * 0.1 ** 0.05 *** 0.01 ) r2

xtpcse rp sng_402 sng_403 sng_405 sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_601 sng_602 sng_603 sng_604 cg_402 cg_403 cg_405 cg_501 cg_502 cg_503 cg_504 cg_505 cg_506 cg_601 cg_602 cg_603 cg_604 gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp


// MULTICOLLINEARITY CHECK
set more off
reg rp sng_402 sng_403 sng_405 sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_601 sng_602 sng_603 sng_604 cg_402 cg_403 cg_405 cg_501 cg_502 cg_503 cg_504 cg_505 cg_506 cg_601 cg_602 cg_603 cg_604 gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif
reg rp sng_ec sng_env sng_hca cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif 
reg rp sng_ec sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif
reg rp sng_402 sng_403 sng_405 sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif
reg rp sng_ec sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp 
estat vif
reg rp sng_ec sng_env sng_601 sng_602 sng_603 sng_604 cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
estat vif

// COINTEGRATION CHECK
set more off
xtcointtest kao rp sng_402 sng_403 sng_405 sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_601 sng_602 sng_603 sng_604 cg_402 cg_403 cg_405 cg_501 cg_502 cg_503 cg_504 cg_505 cg_506 cg_601 cg_602 cg_603 cg_604 gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
xtcointtest kao rp sng_ec sng_env sng_hca cg_pc_usr gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
xtcointtest kao rp sng_ec sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
xtcointtest kao rp sng_402 sng_403 sng_405 sng_env sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp
xtcointtest kao rp sng_ec sng_501 sng_502 sng_503 sng_504 sng_505 sng_506 sng_hca cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp 
xtcointtest kao rp sng_ec sng_env sng_601 sng_602 sng_603 sng_604 cg_ec cg_env cg_hca gdp_pc_usr rr ren_tot serv_gdp pop_den etax_gdp randd_gdp










